#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int leap(int y,int m,int d)
{
	int result = ((y % 4 == 0 && y % 100) || y % 400 == 0);
	return result;
}

int days(int y, int m, int d)
{
	switch (m)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:return 31;
	case 4:
	case 6:
	case 11:return 30;
	case 2:return 28 + leap(y, m, d);
	}
}

void predays(int y, int m, int d)
{
	d -= 1;
	if (d == 0)m -= 1;
	if (m == 0)y -= 1, m = 12;
	if(d==0)d = days(y, m, d);
	printf("%d %d %d\n", y, m, d);
}
void outdays(int y, int m, int d)
{
	d += 1;
	if (d>days(y,m,d))m+=1,d=1;
	if (m == 13)y += 1, m = 1;
	printf("%d %d %d\n", y, m, d);

}

int main()
{
	int y, m, d;
	scanf("%d %d %d", &y, &m, &d);
	predays(y, m, d);
	outdays(y, m, d);

	return 0;
}